package com.demo2do.boyle.common.entity.geo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.core.web.format.PersistentFormat;

/**
 * @author downpour
 */
@Entity
@Table(name = "geo")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@PersistentFormat(key = String.class)
public class Geo {

    @Id
    @GenericGenerator(name = "generator", strategy = "assigned")
    @GeneratedValue(generator = "generator")
    private String code;

    @Enumerated(EnumType.ORDINAL)
    private Level level;

    private String belongs;

    private String name;
    
    private int display;
    
    /** 是否为一线城市 */
    @Column(name = "is_hot")
    private boolean hot;

    /** 开通标志 */
    @Column(name = "is_active")
    private boolean active;

    /** 显示标志 */
    @Column(name = "is_disabled")
    private boolean disabled;

    /**
     * The default constructor
     */
    public Geo() {

    }

    /**
     * 
     * @param code
     * @param name
     * @param belongs
     * @param level
     */
    public Geo(String code, String name, String belongs, Level level) {
        this.code = code;
        this.name = name;
        this.belongs = belongs;
        this.level = level;
    }

    /**
     * 
     * @return
     */
    @Transient
    @JSONField(serialize = false)
    public boolean isCity() {
        return this.level.equals(Level.CITY);
    }
    
    /**
     * 
     * @return active for advertisement
     */
    public Geo active() {
    	this.active = true;
    	return this;
    }

    /**
     * enable for showing
     * 
     * @return
     */
    public Geo enable() {
        this.disabled = false;
        return this;
    }

    /**
     * activate for usage
     * 
     * @param active
     * @return
     */
    public Geo status(boolean active) {
        this.active = active;
        return this;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the level
     */
    public Level getLevel() {
        return level;
    }

    /**
     * @return the belongs
     */
    public String getBelongs() {
        return belongs;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    
    /**
	 * @return the display
	 */
	public int getDisplay() {
		return this.display;
	}
	
	/**
	 * @return the hot
	 */
	public boolean isHot() {
		return this.hot;
	}

    /**
     * @return the active
     */
    public boolean isActive() {
        return active;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param code
     *            the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param level
     *            the level to set
     */
    public void setLevel(Level level) {
        this.level = level;
    }

    /**
     * @param belongs
     *            the belongs to set
     */
    public void setBelongs(String belongs) {
        this.belongs = belongs;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
	 * @param display the display to set
	 */
	public void setDisplay(int display) {
		this.display = display;
	}
	
	/**
	 * @param hot the hot to set
	 */
	public void setHot(boolean hot) {
		this.hot = hot;
	}

    /**
     * @param active
     *            the active to set
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * @param disabled
     *            the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}
